/**
 * @author wn
 * @date 2023/09/19 15:17:44
 * @description: 个人信息 数据 存储
 */

import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useMemberStore = defineStore(
	'member',
	() => {
		// 会员信息
		const member = ref<LoginResult>()

		// 修改会员信息,登陆时
		const setMember = (v: LoginResult) => (member.value = v)

		// 清空会员信息,退出时
		const clearMember = () => (member.value = undefined)

		// 返回
		return { member, setMember, clearMember }
	},
	{
		// persist: true, // 网页端配置
		// 小程序端配置 数据持久化
		persist: {
			storage: {
				getItem(key) {
					return uni.getStorageSync(key)
				},
				setItem(key, value) {
					uni.setStorageSync(key, value)
				},
			},
		},
	}
)
